<template>
	<view class="inv_records">
		<!-- <u-calendar v-model="show" mode="range" btn-type='success' range-color='#26C281'
			range-bg-color='rgba(38, 194, 129, 0.13)' active-bg-color='#26C281' :safe-area-inset-bottom='true'
			@change="change"></u-calendar> -->

		<view class="header-card">

			<view class="words">
				您对本平台使用过程中如有任何问题（如套餐内容、佣金结算、添加代理等），请联系您的专属服务经理。
			</view>
			<view class="mobile">
				<text>电话号：{{superiors_mobile}}</text>
				<view class="r-btn" @click.stop="copyBtn(superiors_mobile)">复制</view>
			</view>
			<view class="wechat">
				<text>微信号：{{superiors_wx}}</text>
				<view class="r-btn" @click.stop="copyBtn(superiors_wx)">复制</view>
			</view>
		</view>
		<view class="team_top">
			<view class="nav">
				<!-- <view class="left" @click="show=true">
					<text class="time" :class="startTime?'time_active':''">{{startTime?startTime:'开始时间'}}</text>
					<text class="line">-</text>
					<text class="time" :class="endTime?'time_active':''">{{endTime?endTime:'结束时间'}}</text>
				</view> -->
				<view class="btn" @click="txtNavBtn(5)">
					<image class="nav-item-image" src="@/static/images/index/icon1.png"></image>
					<view>赚佣必读</view>
				</view>
				<view class="btn" @click="goPath('/pages/order/CreatePoster')">
					<image class="nav-item-image" src="@/static/images/index/icon2.png"></image>
					<view>邀请下级</view>
				</view>
				<view class="btn" @click="txtNavBtn(8,0)">
					<image class="nav-item-image" src="@/static/images/index/icon3.png"></image>
					<view>添加下级</view>
				</view>
				<!-- <view class="btn" @click="txtNavBtn(5,0)">下级查询</view> -->
				<view class="btn" @click="useSearch">
					<image class="nav-item-image" src="@/static/images/index/icon4.png"></image>
					<view>下级查询</view>
				</view>
				<!-- <view class="btn">代理人数：{{total}}</view> -->
			</view>
			<view class="search_box" v-show="search">
				<u-form>
					
					<u-form-item>
						<u-input placeholder="请输入账号" v-model="query.username"  maxlength="40" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入姓名" v-model="query.nickname"  maxlength="11" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入电话号码" v-model="query.phone"  maxlength="40" border></u-input>
					</u-form-item>
					<u-form-item>
						<view class="btn_box">
							<u-button shape="circle" type="error" class="btn reset" @click="reset">重置</u-button>
							<u-button shape="circle" class="btn confirm" @click="confirm">查询</u-button>
						</view>
					</u-form-item>
				</u-form>
			</view>
			<!-- <view class="nav_list">
				<u-tabs :list="navList" height='88' active-color='#26C281' inactive-color='#222222' :is-scroll="false" :current="current" @change="navChange"></u-tabs>
			</view> -->
		</view>

		<view class="no_html" v-if="list.length==0">
			<image src="@/static/images/no_img5.png" mode=""></image>
			<text>没有数据</text>
		</view>
		<!--  -->
		<view v-else>
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="text-header">
					<text class="left topword">{{item.username}}</text>
					<text class="right">本月订单{{item.month_order}}</text>
					<text class="right">总订单{{item.all_order}}</text>
				</view>
				
				<view class="user">					
						<view class="item">代理姓名：{{item.nickname}}</view>
						<view class="item">手机号：{{item.mobile}}</view>
						<view class="item order_num"><text>直推下级数量：{{item.junior_num}}</text><text>间推下级数量：{{item.indirect_num}}</text></view>
						<view class="item">登录时间：{{item.logintime_text}}</view>
						<view class="item">创建时间：{{item.logintime_text}}</view>					
				</view>
				<view class="btns">
					<text class="btn" @click="txtNavBtn(1,item.id)">修改信息</text>
					<!-- <text class="btn" @click="txtNavBtn(2,item.id,item.nickname)">设置佣金</text> -->
					<text class="btn" @click="txtNavBtn(3,item.id)">产品设置</text>
					<text class="btn" @click="txtNavBtn(4,item.id,'',item.is_dl)">TA的订单</text>
				</view>
			</view>
			<view class="mall_loading" v-if="list.length" style="padding-top: 24rpx;">
				<u-loadmore :status="status" color='#999' />
			</view>
		</view>
		<ConfirmReceipt ref="confirm_receipt" @submit='submitBtn'></ConfirmReceipt>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import ConfirmReceipt from '@/components/confirm_receipt/confirm_receipt.vue';
	export default {
		components: {
			ConfirmReceipt
		},
		data() {
			return {
				show: false,
                navList: [{
                					name: '待收货'
                				}, {
                					name: '待付款'
                				}, {
                					name: '待评价'
                				}],
				current: 0,
				id: '',
				info: '',
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				page: 1,
				list: [],
				total:'',
				superiors_mobile:'',
				superiors_wx:'',
				query: {
					username: "",
					nickname: "",
					phone: ""
				},
				search: false,
			};
		},
		onLoad(opt) {
			if (opt.id) {
				this.id = opt.id
			}
		},
		onShow() {
			this.page = 1
			this.getList()
		},
		// onHide(){
		// 	this.$refs.confirm_receipt.closeBtn()
		// },
		methods: {
			
			/**
			 * 点击查询
			 */
			useSearch() {
				this.search = !this.search
			},
			
			/**
			 * 重置
			 */
			reset() {
				this.query = {
					nickname: "",
					username: "",
					phone: ""
				}
				this.getList()
			},
			
			/**
			 * 点击搜索
			 */
			confirm() {
				this.page = 1 
				this.getList()
			},
			goPath(url) {
				uni.navigateTo({
					url: url
				})
			},
			copyBtn(txt) {
			
				uni.setClipboardData({
					data: txt,
					success: function() {
						console.log('success');
					}
				});
			},
			// 列表
			getList() {
				let { query } = this 
				var that = this
				if (that.page == 1) {
					that.$tips.showLoading('加载中')
				} else {
					that.status = 'loading'
				}
				var params = {
					username: that.username,
					nickname: that.nickname,
					mobile: that.mobile,
					...query,
				}
				that.$httpApi.userScorelogIndex(params).then((res) => {
					if (res.code == 1) {
						if (that.page == 1) {
							that.list = []
							that.$tips.hideLoading()
						}
						if (res.data.current_page == res.data.last_page) {
							that.status = 'nomore'
						} else {
							that.status = 'loadmore'
						}
						that.list = that.list.concat(res.data.data)
						that.total = res.data.total
						that.superiors_wx = res.data.superiors_wx
						that.superiors_mobile = res.data.superiors_mobile
					}
				})
			},
			// 查询
			queryBtn() {
				this.page = 1
				this.getList()
			},
			txtNavBtn(type, ids, nickname = '',is_dl='') {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/person/agent_info?ids=' + ids
					})
				} else if (type == 2) {

					this.$refs.confirm_receipt.openBtnThree(ids, nickname)
				} else if (type == 3) {
					uni.navigateTo({
						url: '/pages/order/order?ids=' + ids
					})
				} else if (type == 5) {
					uni.navigateTo({
						url:'/pages/order/text-list?m_type=2'
					})
				} else if(type==4){
					
					uni.navigateTo({
						url: '/pages/order/orderdaili?ids='+ids+'&is_dl='+is_dl
					})
				}else if(type==8){
					uni.navigateTo({
						url: '/pages/person/agent_add'
					})
					
				}else{
					uni.navigateTo({
						url: '/pages/order/orderdaili?ids='+ids
					})
				}
			},

			// 切换
			navChange(index) {
				this.current = index
				this.page = 1
				this.getList()
			},
			// 选择日期
			change(e) {
				this.startTime = e.startDate
				this.endTime = e.endDate
			}
		},
		onReachBottom() {
			if (this.status == 'nomore' || this.status == 'loading') {
				return
			}
			this.page++
			this.getList()
		},
	}
</script>

<style lang="less">
	.search_box {
		width: 100%;
		padding: 0 40rpx;
		.btn_box {
			width: 100%;
			display: flex;
			justify-content: center;
			.btn {
				margin: 10rpx;
				width: 160rpx;
				text-align: center;
			}
			.confirm {
				background-color: #00afaa;
				color: #fff;
			}
		}
	}
	.topword {
		color: #dd0000 !important
	}

	.inv_records {
		width: 100%;

		.header-card {
			margin: 20rpx;
			background: #26C281;
			padding: 20rpx;
			color: #fff;
			border-radius: 10rpx;
			.words{ text-indent: 48rpx;padding:20rpx}

			.mobile {
				padding: 20rpx 0;
				width: 400rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 auto;
				.r-btn{border:1rpx solid #fff;border-radius: 6rpx;padding:6rpx 20rpx;}
			}

			.wechat {
				padding: 20rpx 0;
				width: 400rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 auto;
				.r-btn{border:1rpx solid #fff;border-radius: 6rpx;padding:6rpx 20rpx;}
			}
		}

		.team_top {
			width: 100%;
			background: #fff;
			border-bottom: 2rpx solid #f7f8fa;

			.nav {
				width: 100%;
				// height: 100rpx;
				padding: 20rpx 32rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.left {
					width: 538rpx;
					height: 64rpx;
					padding: 0 30rpx;
					background: #F5F5F5;
					border-radius: 32rpx;
					display: flex;
					align-items: center;
					justify-content: space-around;

					.line {
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #BEBEBE;
					}

					.time {
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #BEBEBE;
					}

					.time_active {
						color: #333;
					}
				}
                .btn {
					// color: #FFFFFF;
					// background: #26C281;
					border-radius: 32rpx;
					padding:15rpx 10rpx;
					width:200rpx;
					text-align: center;
					
					.nav-item-image {
						width: 90rpx;
						height: 90rpx;
					}
				}
				.right {
					width: 132rpx;
					height: 64rpx;
					line-height: 64rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					background: #26C281;
					border-radius: 32rpx;
				}
			}

			.nav_list {
				width: 100%;
				border-bottom: 2rpx solid #f7f8fa;
			}
		}

		.num_list {
			width: 100%;
			margin-bottom: 23rpx;
			padding: 24rpx 0;
			background: #fff;
			display: flex;
			justify-content: space-between;

			.txt {
				flex: 1;
				// width: 100%;
				border-left: 2rpx solid #f7f8fa;

				text {
					display: block;
					width: 100%;
					text-align: center;
				}

				.t_num {
					font-size: 32rpx;
					font-family: OPPOSans-Bold, OPPOSans;
					font-weight: bold;
					color: #222222;
				}

				.t_tip {
					padding-top: 8rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}

			.txt:first-child {
				border-left: none;
			}
		}

		.list {

			margin-top: 1rpx;
			padding: 8rpx 32rpx 32rpx;
			background: #fff;
			margin: 20rpx;
			border-radius: 10rpx;

			.user {
				.item{color:#666;padding:6rpx 0;}
				.order_num{
					display:flex;
					text{
						margin-right:40rpx
					}
				}
			}

			.btns {
				display: flex;
				align-items: center;
				justify-content: center;

				.btn {
					margin: 20rpx 8rpx;
					border-radius: 6rpx;
					border: 1rpx solid #eee;
					padding: 12rpx 18rpx;
					margin-top: 30rpx;
				}
			}

			.text-header {
				width: 100%;
				padding: 24rpx 0;
				display: flex;
				justify-content: space-between;

				.left {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
				}

				.right {
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #999999;
				}

				.color1 {
					color: #FF6230;
				}

				.color2 {
					color: #26C281;
				}
			}
		}
	}
</style>